﻿namespace ExamV5.ManagSys
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmSelectUser : Page
    {
        protected Button butAllDel;
        protected Button butAllSelect;
        protected Button butOneDel;
        protected Button butOneSelect;
        protected Button butQuery;
        protected DropDownList DDLDept;
        protected DropDownList DDLUPDept;
        protected HtmlForm frmuser;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        protected Label labSelectedUserTip;
        protected Label labSelectUserTip;
        protected ListBox LBSelect;
        protected ListBox LBSelected;
        private PublicFun publicFun_0 = new PublicFun();
        protected RadioButtonList RBLDate;
        protected string strEBType = "";
        private string string_0 = "";
        private string string_1 = "";
        private string string_2 = "";
        protected TextBox txtEndDate;
        protected TextBox txtQuery;
        protected TextBox txtStartDate;

        protected void butAllDel_Click(object sender, EventArgs e)
        {
            ListItem item = null;
            for (int i = 0; i < this.LBSelected.Items.Count; i++)
            {
                item = new ListItem(this.LBSelected.Items[i].Text, this.LBSelected.Items[i].Value);
                if (this.LBSelect.Items.IndexOf(item) == -1)
                {
                    this.LBSelect.Items.Add(item);
                }
            }
            this.LBSelected.Items.Clear();
            this.labSelectUserTip.Text = "待选人员<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
            this.labSelectedUserTip.Text = "已选人员<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
        }

        protected void butAllSelect_Click(object sender, EventArgs e)
        {
            int num;
            for (num = 0; num < this.LBSelected.Items.Count; num++)
            {
                if (this.LBSelected.Items[num].Text == "所有人员")
                {
                    base.Response.Write("<script>alert('已选择所有人员,不用再选择！')</script>");
                    return;
                }
            }
            ListItem item = null;
            for (num = 0; num < this.LBSelect.Items.Count; num++)
            {
                item = new ListItem(this.LBSelect.Items[num].Text, this.LBSelect.Items[num].Value);
                if (this.LBSelected.Items.IndexOf(item) == -1)
                {
                    this.LBSelected.Items.Add(item);
                }
            }
            this.LBSelect.Items.Clear();
            this.labSelectUserTip.Text = "待选人员<font color=red>(0)</font>";
            this.labSelectedUserTip.Text = "已选人员<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
        }

        protected void butOneDel_Click(object sender, EventArgs e)
        {
            string str = "";
            if (this.LBSelected.SelectedIndex > -1)
            {
                int num = 0;
                while (num < this.LBSelected.Items.Count)
                {
                    if (this.LBSelected.Items[num].Selected)
                    {
                        if (this.LBSelect.Items.IndexOf(this.LBSelected.Items[num]) == -1)
                        {
                            this.LBSelect.Items.Add(this.LBSelected.Items[num]);
                        }
                        str = str + this.LBSelected.Items[num].Value + "#";
                    }
                    num++;
                }
                string[] strArray = str.Split(new char[] { '#' });
                if (strArray.Length > 1)
                {
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        for (num = 0; num < this.LBSelected.Items.Count; num++)
                        {
                            if (this.LBSelected.Items[num].Value == strArray[i])
                            {
                                this.LBSelected.Items.Remove(this.LBSelected.Items[num]);
                            }
                        }
                    }
                }
            }
            this.labSelectUserTip.Text = "待选人员<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
            this.labSelectedUserTip.Text = "已选人员<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
        }

        protected void butOneSelect_Click(object sender, EventArgs e)
        {
            int num;
            for (num = 0; num < this.LBSelected.Items.Count; num++)
            {
                if (this.LBSelected.Items[num].Text == "所有人员")
                {
                    base.Response.Write("<script>alert('已选择所有人员,不用再选择！')</script>");
                    return;
                }
            }
            string str = "";
            if (this.LBSelect.SelectedIndex > -1)
            {
                num = 0;
                while (num < this.LBSelect.Items.Count)
                {
                    if (this.LBSelect.Items[num].Selected && (this.LBSelected.Items.IndexOf(this.LBSelect.Items[num]) == -1))
                    {
                        this.LBSelected.Items.Add(this.LBSelect.Items[num]);
                        str = str + this.LBSelect.Items[num].Value + "#";
                    }
                    num++;
                }
                string[] strArray = str.Split(new char[] { '#' });
                if (strArray.Length > 1)
                {
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        for (num = 0; num < this.LBSelect.Items.Count; num++)
                        {
                            if (this.LBSelect.Items[num].Value == strArray[i])
                            {
                                this.LBSelect.Items.Remove(this.LBSelect.Items[num]);
                            }
                        }
                    }
                }
            }
            this.labSelectUserTip.Text = "待选人员<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
            this.labSelectedUserTip.Text = "已选人员<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
        }

        protected void butQuery_Click(object sender, EventArgs e)
        {
            this.method_0();
        }

        protected void DDLDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.method_0();
        }

        protected void DDLUPDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DDLDept.Items.Clear();
            this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
            if (this.DDLDept.Items.Count == 0)
            {
                if (!(this.DDLUPDept.SelectedItem.Value == "0"))
                {
                    ListItem item = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                    this.DDLDept.Items.Add(item);
                }
                else
                {
                    ListItem item2 = new ListItem("--所有部门--", "0");
                    this.DDLDept.Items.Insert(0, item2);
                }
            }
        }

        private void method_0()
        {
            string strSql = "";
            if (this.DDLDept.SelectedItem.Value == "0")
            {
                strSql = "select a.UserCode,'['+a.UserCode+']'+a.UserName as UserName  from UserInfo a,DeptInfo b  where a.DeptID=b.ID  and a.flag<>'B'";
            }
            if (this.DDLDept.SelectedItem.Value != "0")
            {
                strSql = "select a.UserCode,'['+a.UserCode+']'+a.UserName as UserName  from UserInfo a,DeptInfo b where a.DeptID=b.ID and (" + this.publicFun_0.GetManagDeptID(this.publicFun_0.CheckString(this.DDLDept.SelectedItem.Value)) + ") and a.flag<>'B'";
            }
            if (this.txtQuery.Text.Trim() != "")
            {
                strSql = strSql + " and (a.UserName like '%" + this.txtQuery.Text.Trim() + "%' or a.UserCode like '%" + this.txtQuery.Text.Trim() + "%' or a.Worker like '%" + this.txtQuery.Text.Trim() + "%' or a.UserGWName like '%" + this.txtQuery.Text.Trim() + "%')";
            }
            if (!(this.RBLDate.SelectedItem.Value == "B"))
            {
                if (!((this.txtStartDate.Text.Trim() != "") ? !(this.txtEndDate.Text.Trim() != "") : true))
                {
                    strSql = strSql + "  and (a.UserAge<>'' and a.UserAge is not null) and (Convert(dateTime,a.UserAge)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + "')  and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + "')>=Convert(dateTime,a.UserAge))";
                }
            }
            else if (!((this.txtStartDate.Text.Trim() != "") ? !(this.txtEndDate.Text.Trim() != "") : true))
            {
                strSql = strSql + "  and (a.JoinWorkDate<>'' and a.JoinWorkDate is not null) and (Convert(dateTime,a.JoinWorkDate)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + "')  and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + "')>=Convert(dateTime,a.JoinWorkDate))";
            }
            strSql = strSql + this.string_2 + " order by a.UserCode";
            this.LBSelect.Items.Clear();
            this.LBSelect.DataTextField = "UserName";
            this.LBSelect.DataValueField = "UserCode";
            this.LBSelect.DataSource = this.publicFun_0.RetrunDataView(strSql);
            this.LBSelect.DataBind();
            if (this.DDLDept.SelectedItem.Value == "0")
            {
                ListItem item = new ListItem("所有人员", "所有人员");
                this.LBSelect.Items.Add(item);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) && (this.httpCookie_0.Value != ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.string_0 = base.Request["strFlag"].ToString();
                this.string_1 = "";
                this.int_0 = 0;
                this.string_2 = "";
                if (base.Request["ID"] != null)
                {
                    this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
                    this.string_1 = base.Request["TypeValue"].ToString();
                    if (this.string_1 == "L")
                    {
                        this.string_2 = " and A.UserCode not in(select UserCode from ExamUser where PaperID=" + this.int_0 + ")";
                    }
                    else if (!(this.string_1 == "W"))
                    {
                        this.string_2 = "";
                    }
                    else
                    {
                        this.string_2 = " and A.UserCode not in(select UserCode from WorkExamUser where PaperID=" + this.int_0 + ")";
                    }
                }
                else
                {
                    this.int_0 = 0;
                    this.string_2 = "";
                }
                this.strEBType = base.Request["EB"].ToString();
                if (!base.IsPostBack)
                {
                    try
                    {
                        this.DDLUPDept.DataTextField = "DeptName";
                        this.DDLUPDept.DataValueField = "ID";
                        if (!(this.httpCookie_2.Value == "C"))
                        {
                            this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where ID=" + this.httpCookie_3.Value + " order by SortInfo,ID");
                        }
                        else
                        {
                            this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where UPID=0  order by SortInfo,ID");
                        }
                        this.DDLUPDept.DataBind();
                        if (this.httpCookie_2.Value == "C")
                        {
                            this.DDLUPDept.SelectedIndex = -1;
                            this.DDLDept.SelectedIndex = -1;
                            ListItem item3 = new ListItem("--所有单位--", "0");
                            ListItem item4 = new ListItem("--所有部门--", "0");
                            this.DDLDept.Items.Insert(0, item4);
                            this.DDLUPDept.Items.Insert(0, item3);
                        }
                        else
                        {
                            this.DDLDept.Items.Clear();
                            this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
                            if (this.DDLDept.Items.Count == 0)
                            {
                                ListItem item2 = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                                this.DDLDept.Items.Add(item2);
                            }
                        }
                        this.method_0();
                        string cmdText = "";
                        switch (base.Request["TypeValue"].ToString())
                        {
                            case "B":
                                if (this.strEBType.Trim() == "B")
                                {
                                    break;
                                }
                                cmdText = "select EditUserCode as UserCode,EditUserName as UserName  from TypeList  where Flag='BookType' and ID=" + this.int_0;
                                goto Label_0760;

                            case "V":
                                if (this.strEBType.Trim() == "B")
                                {
                                    goto Label_0619;
                                }
                                cmdText = "select EditUserCode as UserCode,EditUserName as UserName  from TypeList  where Flag='LessionType' and ID=" + this.int_0;
                                goto Label_0760;

                            case "S":
                                if (this.strEBType.Trim() == "B")
                                {
                                    goto Label_066B;
                                }
                                cmdText = "select EditUserCode as UserCode,EditUserName as UserName  from SubjectInfo  where  ID=" + this.int_0;
                                goto Label_0760;

                            case "P":
                                cmdText = "select StudyUserCode as UserCode,StudyUserName as UserName  from StudyPlanInfo where  ID=" + this.int_0;
                                goto Label_0760;

                            case "N":
                                cmdText = "select BrowUserCode as UserCode,BrowUserName as UserName  from NewsInfo where  ID=" + this.int_0;
                                goto Label_0760;

                            case "Q":
                                cmdText = "select DCUserCode as UserCode,DCUserName as UserName  from OnlineQuest where  ID=" + this.int_0;
                                goto Label_0760;

                            case "G":
                                cmdText = "select  UserCode,UserName from  UserGroup where  ID=" + this.int_0;
                                goto Label_0760;

                            case "F":
                                if (!(this.strEBType.Trim() == "B"))
                                {
                                    goto Label_0727;
                                }
                                cmdText = "select BrowUserCode as UserCode,BrowUserName as UserName  from GradeFolder  where  ID=" + this.int_0;
                                goto Label_0760;

                            case "M":
                                cmdText = "select BrowUserCode as UserCode,BrowUserName as UserName  from SysMenu where  ID=" + this.int_0;
                                goto Label_0760;

                            case "Z":
                                cmdText = "select JoinUserCode as UserCode,JoinUserName as UserName from  ZiSetInfo";
                                goto Label_0760;

                            default:
                                goto Label_0760;
                        }
                        cmdText = "select BrowUserCode as UserCode,BrowUserName as UserName from TypeList  where Flag='BookType' and ID=" + this.int_0;
                        goto Label_0760;
                    Label_0619:
                        cmdText = "select BrowUserCode as UserCode,BrowUserName as UserName  from TypeList  where Flag='LessionType' and ID=" + this.int_0;
                        goto Label_0760;
                    Label_066B:
                        cmdText = "select BrowUserCode as UserCode,BrowUserName as UserName  from SubjectInfo  where  ID=" + this.int_0;
                        goto Label_0760;
                    Label_0727:
                        cmdText = "select EditUserCode as UserCode,EditUserName as UserName  from GradeFolder  where  ID=" + this.int_0;
                    Label_0760:
                        if (cmdText.Trim() != "")
                        {
                            string str = "";
                            string str2 = "";
                            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                            connection.Open();
                            SqlCommand command = new SqlCommand(cmdText, connection);
                            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                            if (reader.Read())
                            {
                                str = reader["UserCode"].ToString();
                                str2 = reader["UserName"].ToString();
                            }
                            reader.Close();
                            command.Dispose();
                            connection.Close();
                            connection.Dispose();
                            string[] strArray = str.Split(new char[] { ',' });
                            string[] strArray2 = str2.Split(new char[] { ',' });
                            this.LBSelected.Items.Clear();
                            for (int i = 0; i < strArray.Length; i++)
                            {
                                if (strArray[i].Trim().Trim() != "")
                                {
                                    ListItem item = new ListItem(strArray2[i].Trim(), strArray[i].Trim());
                                    this.LBSelected.Items.Add(item);
                                }
                            }
                        }
                        this.labSelectUserTip.Text = "待选人员<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
                        this.labSelectedUserTip.Text = "已选人员<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
                    }
                    catch
                    {
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

